package com.system.xingzhi.controller;

import com.system.xingzhi.annotation.LoginToken;
import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.model.User;
import com.system.xingzhi.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@CrossOrigin
@RestController("user")
@Api(value = "/user",tags = {"用户"},description = "用户信息操作")
public class UserController {

    @Autowired
    private UserService userService;
    
    @PostMapping(value="/addUser")
    @ApiOperation(notes = "用户注册",value = "用户注册")
    public ReturnData addUser(@ModelAttribute User user){
        return  userService.insert(user);
    }

    @PostMapping(value="/deleteUser")
    @ApiOperation(notes = "删除用户",value = "删除用户")
    public ReturnData deleteUser(@ApiParam(name = "userId",value = "用户id") @RequestParam("userId") String userId){
        return  userService.deleteByPrimaryKey(userId);
    }

    @PostMapping(value="/updateUser")
    @ApiOperation(notes = "更新用户",value = "更新用户")
    public ReturnData updateUser(@ModelAttribute User user){
        return  userService.updateByPrimaryKey(user);
    }

    @GetMapping(value="/queryUser")
    @ApiOperation(notes = "用户查询",value = "用户查询")
    public ReturnData queryUser(
            @ApiParam(name = "keyWord",value = "关键字") @RequestParam(value = "keyWord",required = false) String keyWord,
            @ApiParam(name = "pageNum",value = "页码") @RequestParam(value="pageNum") Integer pageNum,
            @ApiParam(name = "pageSize",value = "分页条数") @RequestParam(value="pageSize") Integer pageSize
    ){

        return  userService.selectByParameter(keyWord,pageNum,pageSize);
    }
}
